{extend name="layout" /}
{block name="content"}

<style type="text/css">
    .layui-card-body{
        background-color: #fff;
        padding: 10px;
        margin-top: 10px;
        border: 1px solid #e6e6e6;
    }

    .layui-tab-card>.layui-tab-title{
        background-color: #f9f9f9;
        border-bottom: none;
    }
    .layui-tab-content{
        padding: 0;
    }
    .layui-table, .layui-table-view{
        margin: 0;
    }
    .layui-margin-10{
        margin:10px ;
    }
    .layui-layer-page .layui-layer-content{
        overflow: initial;
    }
    /*.layui-table-cell {
        height: auto;
        text-overflow: inherit;
        overflow: visible;
        white-space: normal;
        word-wrap: break-word;
    }*/
</style>
<script src="__STATIC_JS__jquery.form.js" type="text/javascript" charset="utf-8"></script>

<form class="layui-form seller-form"  action="" >

    <div class="layui-form-item">
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="add"><i class="layui-icon">&#xe608;</i>添加</button>
        </div>


        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width:210px;">
                <input type="text" name="title" lay-verify="title" placeholder="输入标题搜索" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-2">
                <select name="is_article" lay-verify="">
                    <option value="">文章</option>
                    <option value="2">已生成</option>
                    <option value="1">未生成</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-2">
                <select name="is_caogao" lay-verify="">
                    <option value="">草稿</option>
                    <option value="2">已生成</option>
                    <option value="1">未生成</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-2">
                <select name="is_pub" lay-verify="">
                    <option value="">发布</option>
                    <option value="2">已发布</option>
                    <option value="1">未发布</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="content-search"><i
                    class="iconfont icon-chaxun"></i>筛选</button>
        </div>
    </div>





</form>

<div class="layui-card-body">
    <div class="layui-tab layui-tab-card" lay-filter="goods-tab" style="margin:0;">
        <div class="layui-tab-content" >
            <table id="goodsTable" lay-filter="goodsTable"></table>
        </div>
    </div>
</div>




<script>
    var table, window_box;
    layui.use(['form', 'layedit','upload', 'laydate','table','element'], function(){
        var upload = layui.upload;
        var element = layui.element;
        var filter = {};

        table = layui.table.render({
            elem: '#goodsTable',
            height: 'full-181',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            url: "{:url('GzhTitle/index')}?_ajax=1",
            id:'goodsTable',
            cols: [[
                {type:'checkbox'},
                {field:'id', width:90, title:'ID', align: 'center'},
                {field:'operating',width:180,title:'操作', align: 'center',templet:function(data){
                        var html = '';
                        html += '<a class="layui-btn layui-btn-xs edit-class" data-id="' + data.id + '">编辑</a>';
                        html += '<a class="layui-btn layui-btn-danger layui-btn-xs del-class" data-id="' + data.id + '">删除</a>';
                        return html;
                    }
                },
                {field:'title', width:200, title:'标题', align: 'center'},
                {field:'keyword', width:500, title:'后缀', align: 'center'},
                {field:'is_article', width:80, title:'文章', align: 'center',templet:function(data){
                        var html = '';
                        if(data.is_article==2){
                            html += '<div class="layui-btn layui-btn-xs layui-btn-normal">已生成</div>';
                        }else if(data.is_article==1){
                            html += '<div class="layui-btn layui-btn-danger layui-btn-xs">未生成</div>';
                        }
                        return html;
                }},

                {field:'is_article', width:80, title:'草稿', align: 'center',templet:function(data){
                        var html = '';
                        if(data.is_caogao==2){
                            html += '<div class="layui-btn layui-btn-xs layui-btn-normal">'+data.gzh_name+'</div>';
                        }else if(data.is_caogao==1){
                            html += '<div class="layui-btn layui-btn-danger layui-btn-xs">未生成</div>';
                        }
                        return html;
                }},

                {field:'is_pub', width:200, title:'发表', align: 'center',templet:function(data){
                        var html = '';
                        if(data.is_pub==2){
                            html += '<div class="layui-btn layui-btn-xs layui-btn-normal">已发表:'+data.public_at+'</div>';
                        }else if(data.is_pub==1){
                            html += '<div class="layui-btn layui-btn-danger layui-btn-xs">未发表</div>';
                        }
                        return html;
                }},

                {field:'created_at', width:200, title:'创建时间', align: 'center'},
            ]]
        });

        //搜索
        layui.form.on('submit(content-search)', function (data) {
            layui.table.reload('goodsTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        layui.form.on('submit(add)', function(data){
            JsGet('{:url("GzhTitle/add")}',function (tpl) {
                if(tpl.status){
                    layer.open({
                        type: 1,
                        area: setpage(850,500),
                        data:'',
                        title: '添加',
                        content: tpl.data,
                        btn:['保存','关闭'],
                        yes:function (index,layero) {
                            var thedata = $('.formData').serialize();
                            JsPost('{:url("GzhTitle/add")}',thedata,function (re) {
                                if(re.status){
                                    layer.msg('保存成功');
                                    layer.close(index);
                                    //userTables.reload();
                                    layui.table.reload('goodsTable');
                                }else{
                                    layer.msg(re.msg);
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(tpl.msg);
                }
            });
            return false;
        });
    });

    //编辑商品
    $(document).on('click', '.edit-class', function(){
        var id = $(this).attr('data-id');
        JsGet('{:url("GzhTitle/edit")}?id='+id,function (tpl) {
            if(tpl.status){
                layer.open({
                    type: 1,
                    area: setpage(850,500),
                    data:'',
                    title: '编辑',
                    content: tpl.data,
                    btn:['保存','关闭'],
                    yes:function (index,layero) {
                        var thedata = $('.formData').serialize();
                        JsPost('{:url("GzhTitle/edit")}',thedata,function (re) {
                            if(re.status){
                                layer.msg('保存成功');
                                layer.close(index);
                                //userTables.reload();
                                layui.table.reload('goodsTable');
                            }else{
                                layer.msg(re.msg);
                            }
                        });
                    }
                });
            }else{
                layer.msg(tpl.msg);
            }
        });
        return false;
    });

    //删除商品
    $(document).on('click', '.del-class', function(){
        var id = $(this).attr('data-id');
        layer.confirm('确认删除吗？', {
            title: '提示', btn: ['确认', '取消'] //按钮
        }, function(){
            delClass(id);
        });
    });

    //删除操作
    function delClass(id){
        JsPost('{:url("GzhTitle/del")}',{id:id},function(e){
            layer.msg(e.msg, {time: 1300}, function(){
                table.reload('goodsTable');
            });
        });
    }

</script>

<script type="text/html" id="hot">
    <input type="checkbox" name="is_hot" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_hot" {{ d.is_hot == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="rec">
    <input type="checkbox" name="is_recommend" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_recommend" {{ d.is_recommend == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="is_able">
    <input type="checkbox" name="is_able" value="{{d.id}}" lay-skin="switch" lay-text="上架|下架" lay-filter="is_able" {{ d.marketable == 1 ? 'checked' : '' }}>
</script>
{/block}